<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
    protected $fillable = [
        'seller_id',
        'type_id',
        'name',
        'desc',
        'stock',
        'max_price',
        'min_price',
        'thumb',
        'status',
        'sale_num'
    ];
    protected $casts = [
        'status'=>'boolean'
    ];
    //
    public function sku()
    {
        return $this->hasMany(GoodsSku::class, 'goods_id', 'id');
    }

    public function goods_type()
    {
        return $this->belongsTo(GoodsType::class, 'type_id', 'id');
    }

    public function getMaxPriceAttribute($value)
    {
        return $value / 100;
    }

    public function getMinPriceAttribute($value)
    {
        return $value / 100;
    }

    public function setMaxPriceAttribute($value)
    {
        $this->attributes['max_price'] = $value * 100;
    }

    public function setMinPriceAttribute($value)
    {
        $this->attributes['min_price'] = $value * 100;
    }
}
